package com.msb.mall.product.controller;

import java.util.Arrays;
import java.util.Map;

import com.msb.common.vo.CommonPageReq;
import com.msb.common.vo.CommonResult;
import com.msb.mall.core.vo.product.AttrResponseVo;
import com.msb.mall.core.vo.product.AttrVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.msb.mall.product.service.AttrService;
import com.msb.common.utils.PageUtils;


/**
 * 商品属性
 *
 * @author leixu
 * @email xuleiwolf@163.com
 * @date 2024-04-19 20:08:58
 */
@RestController
@RequestMapping("product/attr")
public class AttrController {
    @Autowired
    private AttrService attrService;

    @PostMapping("/{attrType}/list/{catelogId}")
    public CommonResult baseList(@RequestBody CommonPageReq<Map<String, Object>> req
            ,@PathVariable("catelogId") Long catelogId
            ,@PathVariable("attrType") String attrType){
        return attrService.queryBasePage(req, catelogId, attrType);
    }

    /**
     * 信息
     * /product/attr/info/${this.dataForm.attrId}
     */
    @RequestMapping("/info/{attrId}")
    //@RequiresPermissions("product:attr:info")
    public CommonResult info(@PathVariable("attrId") Long attrId){
        //AttrEntity attr = attrService.getById(attrId);
        AttrResponseVo responseVo = attrService.getAttrInfo(attrId);
        return CommonResult.success(responseVo);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public CommonResult list(@RequestParam Map<String, Object> params){
        PageUtils page = attrService.queryPage(params);

        return CommonResult.success(null,  page);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public CommonResult save(@RequestBody AttrVO vo){
//    public CommonResult save(@RequestBody AttrEntity attr){
//		attrService.save(attr);
        attrService.saveAttr(vo);

        return CommonResult.success();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public CommonResult update(@RequestBody AttrVO vo){
//    public CommonResult update(@RequestBody AttrEntity attr){
//		attrService.updateById(attr);
		attrService.updateBaseAttr(vo);

        return CommonResult.success();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public CommonResult delete(@RequestBody Long[] attrIds){
		attrService.removeByIds(Arrays.asList(attrIds));

        return CommonResult.success();
    }

}
